﻿using System;
using System.ComponentModel;
using System.Net;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace DiscoveryLogic.UI.Charts.Converters
{
    public class FontWeightConverter:TypeConverter 
    {
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            return typeof(String) == sourceType;
        }

        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            String fontWeightString = value as String;
            PropertyInfo fontProperty = typeof(FontWeights).GetProperty(fontWeightString);
            FontWeightMethod fontWeightMethod = (FontWeightMethod)Delegate.CreateDelegate(typeof(FontWeightMethod), fontProperty.GetGetMethod());
            return fontWeightMethod();
        }
        private delegate FontWeight FontWeightMethod();
    }
}
